package in.blogspot.khurram2java;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class InfoList extends ListActivity{
	DbAdapter dbAdapter;
	List<Info> info;
	String isbnString;
	String nameString;
	String emailString;
	String authorString;
	String styleString;
	ListView list;
	static final String KEY_ISBN = "isbn";
	static final String KEY_NAME = "name"; 
	static final String KEY_EMAIL = "email";
	static final String KEY_AUTHOR = "author";
	static final String KEY_STYLE = "style";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.list);
	  List<HashMap<String, String>> entryList = new ArrayList<HashMap<String, String>>();
	  String[] from = new String[] {KEY_ISBN , KEY_NAME, KEY_EMAIL,KEY_AUTHOR , KEY_STYLE};
      int[] to = new int[] {  R.id.Isbn,R.id.userNameText, R.id.emailText,R.id.Author ,  R.id.Style,};
	  dbAdapter = new DbAdapter(this);
	  info = dbAdapter.getAllInfo();
	  for (Info inf : info) {
		  isbnString = inf.getIsbn();
		  nameString = inf.getName();
		  emailString = inf.getEmail();
		  authorString = inf.getAuthor();
		  styleString = inf.getStyle();
		  
		// creating new HashMap
		  HashMap<String, String> map = new HashMap<String, String >();
		// adding each child node to HashMap key => value
		  map.put(KEY_ISBN, isbnString);
		  map.put(KEY_NAME, nameString);
		  map.put(KEY_EMAIL, emailString);
		  map.put(KEY_AUTHOR, authorString);
		  map.put(KEY_STYLE, styleString);
		// adding HashList to ArrayList
		  entryList.add(map);
	  }
	  
	 
	  ListAdapter adapter = new SimpleAdapter(getApplicationContext(), entryList, R.layout.list_view, from, to);

      // Bind to our new adapter.
      setListAdapter(adapter);
	  
	 }
	
	
}
